# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=rauc
pkgver=1.9
pkgrel=1
pkgdesc="Safe and secure software updates for embedded Linux"
arch=(loong64 x86_64)
url="https://rauc.io"
license=(LGPL2.1)
depends=(
  gcc-libs
  glibc
  libnl
  openssl
)
makedepends=(
  curl
  dbus
  glib2
  json-glib
  python
  systemd
  util-linux
)
checkdepends=(squashfs-tools)
optdepends=(
  'casync: for casync conversion support'
  'cryptsetup: for disk encryption support'
  'dosfstools: for creating and checking FAT filesystems'
  'e2fsprogs: for creating and checking ext2/3/4 filesystems'
  'efibootmgr: for interacting with EFI boot manager'
  'grub: for GRUB support'
  'mtd-utils: for interacting with MTD devices'
  'squashfs-tools: for creating and inspecting bundles'
  'uboot-tools: for u-boot support'
)
source=(https://github.com/rauc/rauc/releases/download/v$pkgver/$pkgname-$pkgver.tar.xz{,.asc})
sha512sums=('461c545619d5827dc0190e0134df04afaf3d10e235b5e521a81be0759aeb8c8452ee5ab8a5a627265d8878fd25f614ad6b8fabaa085fb203ec7c5b4e3e8448a3'
            'SKIP')
b2sums=('a42996be51b1afd34be7e72a257d3932bbc4328ced5efa1190a6f5f74296c427e49b819bbd477a8a46a07fa12a4e616278e3370241413989a1a4889f690a84d4'
        'SKIP')
validpgpkeys=("977843FD5C3EBF76BAD4008EA58CC53DBF05E090")  # Jan Lübbe <jlu@pengutronix.de>

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --libexecdir=/usr/lib
    --enable-gpt
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  make
}

check() {
  make -k check -C $pkgname-$pkgver
}

package() {
  depends+=(
    curl libcurl.so
    glib2 lib{gobject,gio,glib}-2.0.so
    json-glib libjson-glib-1.0.so
    util-linux-libs libfdisk.so
  )

  make DESTDIR="$pkgdir/" install -C $pkgname-$pkgver
  install -vdm 755 "$pkgdir/etc/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/contrib/{grub.conf,uboot.sh} -t "$pkgdir/usr/share/doc/$pkgname/"
}
